package com.wanmei.service;


import com.wanmei.mapper.AttributevalueMapper;
import com.wanmei.mapper.ProductkuidMapper;
import com.wanmei.pojo.Attributevalue;
import com.wanmei.pojo.ProductStoreNum;
import com.wanmei.pojo.Productkuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ProductKuidService")
public class ProductKuidService {
    @Autowired
    private ProductkuidMapper productkuidMapper;
    @Autowired
    private AttributevalueMapper attributevalueMapper;

    public Productkuid getProductSum(int pid, int vid) {
        return productkuidMapper.getAllByPidAndVid(pid, vid);
    }


    public List<ProductStoreNum> getProductStoreNum(int pid) {
        return productkuidMapper.getProductStoreByPidAndVid(pid);
    }

    //获取具体型号的内存
    public Integer getStoreNumBySize(int pid, int vid) {
        return productkuidMapper.getStoreNumByPidAndVid(pid, vid);
    }

//    /**
//     * 修改具体型号的库存 具体输入值在前端判断就行
//     */
//    public int saveStoreNumBySize(Productkuid productkuid) {
//        return productkuidMapper.updateByExampleSelective(productkuid);
//    }

    /**
     * 添加默认
     */
    public void insertBydefault(Productkuid productkuid){
        productkuidMapper.insertSelective(productkuid);
    }
    /**
     * 修改库存
     */
    public void updateByPidAndVid(Productkuid productkuid){
        productkuidMapper.updateByPidAndVid(productkuid);
    }
    /**
     * 添加型号
     *
     * @param attributevalue
     * @param storeNum
     * @param pid
     * @return
     */
    public int saveStoreNumAndVname(Attributevalue attributevalue, int storeNum, int pid) {
        attributevalueMapper.insertSelective(attributevalue);
        System.out.println("vid:" + attributevalue.getVid() + "  ");
        Productkuid productkuid = new Productkuid();
        productkuid.setVid(attributevalue.getVid());
        productkuid.setPid(pid);
        productkuid.setStorenum(storeNum);
        return productkuidMapper.updateByExampleSelective(productkuid);
    }

}
